package contract.user.client;

import java.util.List;

import javax.xml.ws.soap.SOAPFaultException;

import org.junit.Before;
import org.junit.Test;

import user.client.AddUserException_Exception;
/**
 * wsimport -s d:\wsdl\ -p userClient 
 * http://localhost:8081/WebService/service/userService?wsdl
 * @author ddf 2016年10月9日上午11:35:31
 *
 */
public class TestService {
	private ContractUserService cus;
	
	@Before
	public void init() {
		ContractUserServiceImplService csis = new ContractUserServiceImplService();
		cus = csis.getContractUserServiceImplPort();
	}
	
	@Test
	public void testAddUser() {
		try {
			User user = new User();
			user.setUsername("ddf2");
			user.setPassword("123456");
			user.setEmail("1041765757@qq.com");
			user.setTelNo("18356784598");
			cus.addUser(user);
			
			User user1 = new User();
			user1.setUsername("ddf12");
			user1.setPassword("1234561");
			user1.setEmail("10417657571@qq.com");
			user1.setTelNo("183567845981");
			cus.addUser(user1);
			// 异常错误信息没有获取到
		} catch(RepetUserException_Exception e) {
			System.out.println(e.getMessage());
		} catch(SOAPFaultException e) {
			System.out.println(e.getMessage());
		}
	}
	
	@Test
	public void deleteUser() {
		String username = "ddf";
		cus.deleteUser(username);
		testGetAllUser();
	}
	
	@Test
	public void testGetAllUser() {
		List<User> usList = cus.getAllUser();
		if(usList != null && usList.size() > 0) {
			for(User user : usList) {
				System.out.println("username:" + user.getUsername() + "--password:"
						+ user.getPassword() + "--email:" + user.getEmail()
						+ "--telNo:" + user.getTelNo());
			}
		} else {
			System.out.println("当前没有用户！");
		}
	}
}
